Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure New HAProxy to Direct Traffic to Redis with Role: Slave #37

Closed
wants to merge 3 commits into from

Conversation

rurkss
Copy link

@rurkss rurkss commented Jan 15, 2024

This Pull Request presents a different method compared to Add Redis Slave Endpoint to HAProxy Service configuration.
Here, the redis-operator will establish a completely new HAProxy service, designed to route traffic specifically to Redis instances functioning as slaves.

@rurkss rurkss self-assigned this Jan 15, 2024
@rurkss rurkss requested a review from a team as a code owner January 15, 2024 19:23
@rurkss rurkss changed the title Configure New HAProxy to Direct Traffic to Redis with Role: Slave. Configure New HAProxy to Direct Traffic to Redis with Role: Slave Jan 15, 2024
Comment on lines +55 to +56
redisHAProxyName = "redis-haproxy"
redisSlaveHAProxyName = "redis-s-haproxy"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had you considered putting these in the constants with the other resource naming conventions therein?

Given how other resources the operator names other resource, I'd expect the full generated name of the haproxy bits to be something like:
Redis Failover Redis Master HAproxy

rfrmh-[redis-failover-name] 

Redis Failover Redis Master HAproxy

rfrsh-[redis-failover-name]

Comment on lines +68 to +74
func GetHAProxyRedisLabels() map[string]string {
return haproxyRedisLabels
}

func GetHAProxyRedisSlaveLabels() map[string]string {
return haproxyRedisSlaveLabels
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't reuse the existing generateRedisMasterRoleLabel and generateSlaveRoleLabel functions for this?

func generateRedisMasterRoleLabel() map[string]string {
return map[string]string{
redisRoleLabelKey: redisRoleLabelMaster,
}
}
func generateRedisSlaveRoleLabel() map[string]string {
return map[string]string{
redisRoleLabelKey: redisRoleLabelSlave,
}
}


func generateHAProxyDeployment(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *appsv1.Deployment {

name := rf.GenerateName(redisHAProxyName)
name := rf.GenerateName(labels[rfLabelInstance])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we don't follow the convention for generating names of resource established in the names.go here?

// GetRedisName returns the name for redis resources
func GetRedisName(rf *redisfailoverv1.RedisFailover) string {
return generateName(redisName, rf.Name)
}

Had we considered adding a name generators for the HAProxy bits?

@@ -29,6 +32,8 @@ func (w *RedisFailoverHandler) Ensure(rf *redisfailoverv1.RedisFailover, labels
}

if rf.Spec.Haproxy != nil {
labels = util.MergeLabels(labels, rfservice.GetHAProxyRedisLabels())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type of thing usually happens down in the generators, no?

Comment on lines +164 to +167
redisRole := "role:master"
if labels[rfLabelInstance] == redisSlaveHAProxyName {
redisRole = "role:slave"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of duplicate branching and inferring based on "role" in the HAProxy resource generators - implicitly in the deployment, and again explicitly in the service generator.

Had you considered exposing explicit functions for creating the master and slave harpoxy bits and levae it up to the caller to decide which one they want; similar to the pattern used the existing Master and Slave service generators?

func generateRedisMasterService(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.Service {

func generateRedisSlaveService(rf *redisfailoverv1.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.Service {


var (
haproxyRedisSlaveLabels = map[string]string{
rfLabelInstance: redisSlaveHAProxyName,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the existing "redisfailovers.databases.spotahome.com/component" and "redisfailovers.databases.spotahome.com/redisfailovers-role" labels not be enough and/or appropriate here?

AFAIK, the semantics of the app.kuebernetes.io/instance label are that its supposed to unique to the running resource:

Description: A unique name identifying the instance of an application
Example: mysql-abcxzy
-- https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels

Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
Selector: map[string]string{
"app.kubernetes.io/component": "redis",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low priority context query.

I think this is a "preexisting condition" but any idea why HAProxy components of the RedisFailver would receive the app.kubernetes.io/component label value of "redis" instaed of something like "proxy" or "redis-proxy"?

@rurkss rurkss closed this Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants